package com.learn.metrics.type.gauge;

import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.RandomUtil;
import com.learn.metrics.util.MetricUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 度量指标
 * <p>简单的值返回,例如: 队列大小、自定义值等</p>
 * @author XuYang
 * @since 2025/2/19 9:19
 */
public class GaugeExample {

    public static void start() {
        MetricUtil.startReporter(2);
        List<String> list = new ArrayList<>();
        MetricUtil.REGISTRY.gauge("gauges", () -> list::size);
        int count = 0;
        while (count++ < 100) {
            list.add("1");
            ThreadUtil.sleep(RandomUtil.randomInt(500, 1000));
        }

    }
}
